<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%>
<div id="cc_providers" class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'数据字典管理',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
			    <td class="screen-n"><span>类别</span></td>
				<td class="screen-n">
					<input type="text" id="s_keyCatagory" class="screen-input" style="width:150px"onkeydown="pms.kd13('initDictionary')">
				</td>
				<td class="screen-n"><span>键</span></td>
				<td class="screen-n">
					<input type="text" id="s_key" class="screen-input" style="width:150px"onkeydown="pms.kd13('initDictionary')">
				</td>
				<td class="screen-n"><span>值</span></td>
				<td class="screen-n">
					<input type="text" id="s_value" class="screen-input" style="width:150px"onkeydown="pms.kd13('initDictionary')">
				</td>
				
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initDictionary()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
					<input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>  
<script>

var toolbar = [
 <se:hasPermissions actCode="ADD" >
  {
	text:'新增',
    iconCls:'ext-icon-note_add',
    handler:function(){
    	openDictionaryAddWindow();
    }
  },
 </se:hasPermissions>
 <se:hasPermissions actCode="DELETE" >
{
	text:'删除',
    iconCls:'ext-icon-note_delete',
    handler:function(){
    	var rows = dictionaryTable.getCheckedData();
		if(rows==null || rows.length==0){
			alertWarning("请选中要删除的数据!");
			return;
		}
		if(confirm("确定批量删除?")){
			var ids = [];
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].dictionaryId);
			}
			var dictionaryIdList = ids.toString();
			var param = {"dictionaryIdList":dictionaryIdList};
			$.pmsAjax({
				url:'<c:url value="/dictionary/deleteMultipleEmSDictionary.do"/>',
				data:param,
				success:function(data){
					if(data.code=="200"){
						alertShow("批量删除成功！");
						dictionaryTable.refresh();
					}else{
						alertError(data.result);
					}
				}
			});
		}
    }
}
</se:hasPermissions>
];
var dictionaryTable;
$(function(){
	initDictionary();
});
function getParams(){
	var queryParamss = {
			"keyCatagory":$('#s_keyCatagory').val(), 
			"key":$('#s_key').val(), 
			"value":$('#s_value').val()
	    };
    return queryParamss;
}
function initDictionary(){
	dictionaryTable = $('#tableGrid').pDataGrid({
		toolbar:toolbar,
		columns:[[
				   {field:'ck',checkbox:true},
	               {field:'keyCatagory',title:'字典分类',align:'center'},
	               {field:'title',title:'标题',align:'center'},
	               {field:'key',title:'键',align:'center'},
	               {field:'value',title:'值',align:'center',formatter:function(value,row){
						if(row.keyCatagory=="图片"){
							return '<a href="'+value+'" target="_blank">预览</a>';
						}else{
							return value;
						}
		           }},
	               
	               {field:'status',title:'是否启用',align:'center',formatter:function(value){
						if(value=="0"){
							return '否';
						}else{
							return '是';
						}
		           }},
		           {field:'notes',title:'备注',align:'center'},
		           {field:'action',title : '操作',align : 'center',
						formatter : function(value, row, index) {
							var str = '';
							<se:hasPermissions actCode="UPDATE" >
								str += ' <img class="iconImg ext-icon-note_edit" title="编辑" onclick="openDictionaryUpdateWindow('+row.dictionaryId+');"/>';
							</se:hasPermissions>
							<se:hasPermissions actCode="DELETE" >
								str += ' <img class="iconImg ext-icon-note_delete" title="删除" onclick="deleteDictionary('+row.dictionaryId+',' + index + ');"/>';
							</se:hasPermissions>
								return str;
						}
					} 
		          ]],
		    url:'<c:url value="/dictionary/searchPageDictionary.do" />',  
		    pagination:true,//分页控件
		    pageSize:30,
		    singleSelect:false,
		    rownumbers:true,
		    queryParams:getParams(),
			onDblClickRow:function(index,row){
				openDictionaryUpdateWindow(row.dictionaryId);
			}
		    
	}); 
}

function openDictionaryAddWindow(){
	$.pmsDialog({
		id:"w_dictionary_detail",
		title:'新增字典',
		method:'post',
		href:'<c:url value="/views/jsp/sys/dictionary/dictionary_detail_s.jsp"/>',
		width:750,
		isIf:true,
		fit:true,
		height:420
	});
}
function openDictionaryUpdateWindow(code){
	var params = {"code":code};
	$.pmsDialog({
		id:"w_dictionary_detail",
		title:'修改字典',
		method:'post',
		params:params,
		isIf:true,
		href:'<c:url value="/views/jsp/sys/dictionary/dictionary_detail_s.jsp"/>',
		width:750,
		fit:true,
		height:420
	}); 
}

function deleteDictionary(code,i){
	if(confirm("确定删除?")){
		var param = {"dictionaryId":code};
		$.pmsAjax({
			url:'<c:url value="/dictionary/deleteEmSDictionary.do"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					alertShow("删除成功");
					dictionaryTable.refresh();
				}else{
					alertError(data.result);
				}
			}
		});
	}
}
//导出
function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/dictionary/searchPageEmSDictionaryExcel.do"/>',getParams());
} 
	
</script>
